package chixing.day11.clone_demo;

public class Book {
    private int bookId;
    private String bookName;
    private float bookPrice;
    public Book(){}

    public Book(String bookName, float bookPrice) {
        this.bookName = bookName;
        this.bookPrice = bookPrice;
    }

    public Book(int bookId, String bookName, float bookPrice) {
        this.bookId = bookId;
        this.bookName = bookName;
        this.bookPrice = bookPrice;
    }

//clone 重写object的clone
    /**
     * 1.new instance : Book enwBook = new Book();
     * 1.copy field value
     * 浅克隆
     *  克隆的属性 都是基本数据类型 + String
     * @return
     * @throws CloneNotSupportedException
     */
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Book newBook = new Book();
        newBook.bookId = this.bookId;
        newBook.bookName = this.bookName;
        newBook.bookPrice = this.bookPrice;
        return newBook;
    }

    public int getBookId() {
        return bookId;
    }

    public void setBookId(int bookId) {
        this.bookId = bookId;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public float getBookPrice() {
        return bookPrice;
    }

    public void setBookPrice(float bookPrice) {
        this.bookPrice = bookPrice;
    }

    @Override
    public String toString() {
        return "Book{" +
                "bookId=" + bookId +
                ", bookName='" + bookName + '\'' +
                ", bookPrice=" + bookPrice +
                '}';
    }
}
